﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ChartTools;

namespace Benefit.Tools.ChartAtManager
{
    public class ChartManager
    {
        public static string CompanyDayBar(List<Models.Sys.Groups> groups, List<Models.Day.GroupDayChange> groupDayChanges)
        {
            List<ChartTools.MSBar3DData> datas = new List<ChartTools.MSBar3DData>();

            foreach (Models.Sys.Groups g in groups)
            {
                var gms = groupDayChanges.Where(a => a.GroupId == g.Id).FirstOrDefault();
                ChartTools.MSBar3DData data = new ChartTools.MSBar3DData();
                data.SeriesName = g.GroupName;
                data.datas.Add(Convert.ToDecimal(gms.Profit));
                data.datas.Add(Convert.ToDecimal(gms.DayCount));
                data.datas.Add(Convert.ToDecimal(gms.Free));
                datas.Add(data);
                data = new ChartTools.MSBar3DData();
            }
            List<string> Labels = new List<string>();
            Labels.Add("平仓盈亏");
            Labels.Add("净利润");
            Labels.Add("手续费");
            ChartTools.MSBar3D pie3d = new ChartTools.MSBar3D(Labels, datas, "GroupBar", "showflash", "盈利占比");
            return pie3d.ToString();
        }

        public static string GroupBar(List<Models.View.OperatorDayChange> changes)
        {
            List<ChartTools.MSBar3DData> datas = new List<ChartTools.MSBar3DData>();


            foreach (Models.View.OperatorDayChange change in changes)
            {
                ChartTools.MSBar3DData data = new ChartTools.MSBar3DData();
                data.SeriesName = change.Operator.UName;
                data.datas.Add(Convert.ToDecimal(change.Profit));
                data.datas.Add(Convert.ToDecimal(change.DayCount));
                data.datas.Add(Convert.ToDecimal(change.Free));
                datas.Add(data);
                data = new ChartTools.MSBar3DData();
            }
            List<string> Labels = new List<string>();
            Labels.Add("平仓盈亏");
            Labels.Add("净利润");
            Labels.Add("手续费");
            ChartTools.MSBar3D pie3d = new ChartTools.MSBar3D(Labels, datas, "GroupBar", "showflash", "盈利占比");
            return pie3d.ToString();
        }


        /// <summary>
        /// 交易员月对比图像(OK)
        /// </summary>
        /// <param name="month"></param>
        /// <param name="year"></param>
        /// <param name="operatorid"></param>
        /// <param name="db"></param>
        /// <returns></returns>
        public static string GroupDayDiffBar(List<Models.View.OperatorDayChange> operatorChanges)
        {
            List<ChartTools.Column3DData> datas = new List<ChartTools.Column3DData>();
            if (operatorChanges.Count() > 0)
            {
                double allprofit = 0f;
                double allfree = 0f;
                double alldaycount = 0f;
                foreach (Models.View.OperatorDayChange opChange in operatorChanges)
                {
                    allprofit += opChange.Profit;
                    allfree += opChange.Free;
                    alldaycount += opChange.DayCount;
                }
                ChartTools.Column3DData data = new ChartTools.Column3DData();
                data.Name = "平仓盈亏";
                data.Value = Convert.ToDecimal(allprofit);
                datas.Add(data);
                data = new ChartTools.Column3DData();
                data.Name = "净利润";
                data.Value = Convert.ToDecimal(alldaycount);
                datas.Add(data);
                data = new ChartTools.Column3DData();
                data.Name = "手续费";
                data.Value = Convert.ToDecimal(allfree);
                datas.Add(data);
            }
            else
            {
                ChartTools.Column3DData data = new ChartTools.Column3DData();
                data.Name = "平仓盈亏";
                data.Value = 0;
                datas.Add(data);
                data = new ChartTools.Column3DData();
                data.Name = "净利润";
                data.Value = 0;
                datas.Add(data);
                data = new ChartTools.Column3DData();
                data.Name = "手续费";
                data.Value = 0;
                datas.Add(data);
            }

            ChartTools.Column3D pie3d = new ChartTools.Column3D("收益对比图", "", "", datas, "", "GroupDayDiffBar", "showflash2");
            return pie3d.ToString();
        }


        /// <summary>
        /// 首页上面的收益按小时分布曲线
        /// </summary>
        /// <param name="tradeHistoryId"></param>
        /// <param name="operatorid"></param>
        /// <returns></returns>
        public static string GetTodayBenefitString(Models.View.OperatorDayTradeInfo info)
        {
            ChartTools.Col3DLineDY3Data data = new ChartTools.Col3DLineDY3Data();
            data.ColName = "平仓盈亏";
            data.LineName = "累计平仓盈亏";


            List<double> coldatas = new List<double>();
            List<Models.View.OperatorDayTradeInfoData> datas = info.Datas;
            foreach (Models.View.OperatorDayTradeInfoData a in datas)
            {
                coldatas.Add(a.SumValue);
            }

            data.ColDatas = coldatas;
            List<double> coldatas2 = new List<double>();

            for (int i = 0; i < coldatas.Count; i++)
            {
                double temp = 0f;
                for (int j = 0; j <= i; j++)
                {
                    temp += coldatas[j];
                }
                coldatas2.Add(temp);

            }
            data.LineDatas = coldatas2;
            List<string> names = new List<string>();
            names.Add("9:30");
            names.Add("10:00");
            names.Add("10:30");
            names.Add("11:00");
            names.Add("13:30");
            names.Add("14:00");
            names.Add("14:30");
            names.Add("15:00");
            data.Labels = names;
            ChartTools.Col3DLineDY3 d3 = new ChartTools.Col3DLineDY3(data, "TodayBenefit", "showflash", "收益示意图");
            return d3.ToString();
        }

        /// <summary>
        /// 汇总信息上面的品种收益饼图
        /// </summary>
        /// <param name="tradeHistoryId"></param>
        /// <param name="operatorid"></param>
        /// <param name="db"></param>
        /// <returns></returns>
        public static string ProductPie(List<Models.View.OperatorDayProductInfo> infos)
        {
            List<ChartTools.Pie3DData> datas = new List<ChartTools.Pie3DData>();

            foreach (Models.View.OperatorDayProductInfo info in infos)
            {
                var queryExist = datas.Where(a => a.Label.Equals(info.ProductId));
                if (queryExist.Count() == 0)//如果该品种没有在列表中
                {
                    ChartTools.Pie3DData data = new ChartTools.Pie3DData();
                    data.Label = info.ProductId + " 盈利";
                    double allsum = infos.Where(a => a.ProductId.Equals(info.ProductId)).Sum(a => a.Profit);

                    data.IsSelected = false;

                    data.Value = allsum;
                    if (data.Value > 0)
                    {
                        datas.Add(data);
                    }
                }

            }
            if (datas.Count == 0)//如果当日品种交易情况都是亏损
            {
                foreach (Models.View.OperatorDayProductInfo info in infos)
                {
                    var queryExist = datas.Where(a => a.Label.Equals(info.ProductId));
                    if (queryExist.Count() == 0)//如果该品种没有在列表中
                    {
                        ChartTools.Pie3DData data = new ChartTools.Pie3DData();
                        data.Label = info.ProductId + " 亏损";
                        double allsum = infos.Where(a => a.ProductId.Equals(info.ProductId)).Sum(a => a.Profit);

                        data.IsSelected = false;

                        data.Value = Math.Abs(allsum);
                        datas.Add(data);
                    }

                }
            }
            ChartTools.Pie3D pie3d = new ChartTools.Pie3D(datas, "ProductPie", "showflash2", "品种比率图", 230);
            return pie3d.ToString();
        }

        /// <summary>
        /// 交易员日分时交易信息
        /// </summary>
        /// <param name="info">盈利的日交易信息</param>
        /// <returns></returns>
        public static string BenefitTimePie(Models.View.OperatorDayTradeInfo info, string playdiv, string title, string functionName)
        {
            List<ChartTools.Pie3DData> datas = new List<ChartTools.Pie3DData>();
            ChartTools.Pie3D pie3d = null;
            ChartTools.Pie3DData data = new ChartTools.Pie3DData();
            var query3 = info.Datas.Where(a => a.SumValue > 0);
            if (query3.Count() == 0)
            {
                data = new ChartTools.Pie3DData();
                data.Label = "没有记录";
                data.IsSelected = false;
                data.Value = 1;
                datas.Add(data);
            }
            else
            {
                data = new ChartTools.Pie3DData();
                data.Label = "9:00-9:30";
                data.Value = info.Datas.Where(a => a.Clock == 1).First().SumValue;
                // data.Color = "59a53c";
                if (data.Value > 0)
                {
                    datas.Add(data);
                }
                data = new ChartTools.Pie3DData();
                data.Label = "9:30-10:00";
                data.Value = info.Datas.Where(a => a.Clock == 2).First().SumValue;
                //    data.Color = "9bbc8e";
                if (data.Value > 0)
                {
                    datas.Add(data);
                }
                data = new ChartTools.Pie3DData();
                data.Label = "10:00-10:30";
                data.Value = info.Datas.Where(a => a.Clock == 3).First().SumValue;
                //   data.Color = "184407";
                if (data.Value > 0)
                {
                    datas.Add(data);
                }
                data = new ChartTools.Pie3DData();
                data.Label = "10:30-11:00";
                data.Value = info.Datas.Where(a => a.Clock == 4).First().SumValue;
                //  data.Color = "212c1c";
                if (data.Value > 0)
                {
                    datas.Add(data);
                }
                data = new ChartTools.Pie3DData();
                data.Label = "13:00-13:30";
                data.Value = info.Datas.Where(a => a.Clock == 5).First().SumValue;
                //   data.Color = "194208";
                if (data.Value > 0)
                {
                    datas.Add(data);
                }
                data = new ChartTools.Pie3DData();
                data.Label = "13:30-14:00";
                data.Value = info.Datas.Where(a => a.Clock == 6).First().SumValue;
                //   data.Color = "148c0e";
                if (data.Value > 0)
                {
                    datas.Add(data);
                }
                data = new ChartTools.Pie3DData();
                data.Label = "14:00-14:30";
                data.Value = info.Datas.Where(a => a.Clock == 7).First().SumValue;
                //    data.Color = "3a4f39";
                if (data.Value > 0)
                {
                    datas.Add(data);
                }
                data = new ChartTools.Pie3DData();
                data.Label = "14:30-15:00";
                data.Value = info.Datas.Where(a => a.Clock == 8).First().SumValue;
                //  data.Color = "758b74";
                if (data.Value > 0)
                {
                    datas.Add(data);
                }
                double maxValue = 0;
                if (datas.Count > 0)
                {
                    maxValue = datas.Max(a => a.Value);
                }
                foreach (ChartTools.Pie3DData a in datas)
                {
                    if (a.Value == maxValue)
                    {
                        a.IsSelected = true;
                    }
                    else
                    {
                        a.IsSelected = false;
                    }
                }
            }


            pie3d = new ChartTools.Pie3D(datas, functionName, playdiv, title, 240);

            return pie3d.ToString();
        }

        public static string WinAndLose(Models.View.OperatorDayChange change)
        {
            List<ChartTools.Pie3DData> datas = new List<ChartTools.Pie3DData>();
            ChartTools.Pie3DData data = new ChartTools.Pie3DData();
            data.Label = "盈利";
            data.IsSelected = true;
            data.Value = change.SumWin;
            //  data.Color = "df0940";
            datas.Add(data);
            data = new ChartTools.Pie3DData();
            data.Label = "亏损";
            data.IsSelected = false;
            data.Value = Math.Abs(change.SumLost);
            //    data.Color = "3d8e19";
            datas.Add(data);
            ChartTools.Pie3D pie3d = new ChartTools.Pie3D(datas, "WinAndLose", "showflash3", "", 120);
            return pie3d.ToString();

        }

        /// <summary>
        /// 持仓分析上面的成交笔数按时间分布
        /// </summary>
        /// <returns></returns>
        public static string GetChartBillCountOnCCFX(Models.View.OperatorDayTradeInfo info)
        {
            ChartTools.Col3DLineDY3Data data = new ChartTools.Col3DLineDY3Data();
            data.ColName = "成交笔数";
            List<double> coldatas = new List<double>();

            foreach (Models.View.OperatorDayTradeInfoData i in info.Datas)
            {
                coldatas.Add(i.BillCount);
            }

            data.ColDatas = coldatas;
            List<string> names = new List<string>();
            names.Add("9:30");
            names.Add("10:00");
            names.Add("10:30");
            names.Add("11:00");
            names.Add("13:30");
            names.Add("14:00");
            names.Add("14:30");
            names.Add("15:00");
            data.Labels = names;
            ChartTools.Col3DLineDY3 d3 = new ChartTools.Col3DLineDY3(data, "BillCount", "showflash3", "成交笔数按时间分布", "changeMonth", "");
            return d3.ToString();
        }

        /// <summary>
        /// 持仓时间与收益率的关系图
        /// </summary>
        /// <param name="tradeHistoryId"></param>
        /// <param name="operatorId"></param>
        /// <param name="db"></param>
        /// <returns></returns>
        public static string GetChartYieldOnCCFX(List<Models.View.OperatorYieldInHoldTime> lists)
        {
            List<string> names = new List<string>();
            lists.OrderBy(a => a.HoldTime);
            foreach (Models.View.OperatorYieldInHoldTime time in lists)
            {
                names.Add(time.HoldTime + "秒");
            }

            List<ChartTools.Series> datas = new List<ChartTools.Series>();
            ChartTools.Series data = new ChartTools.Series();
            //  data.Color = "1D8BD1";
            data.Name = "收益率";
            List<double> ds = new List<double>();
            foreach (Models.View.OperatorYieldInHoldTime time in lists)
            {
                ds.Add(time.Yield);
            }
            data.Datas = ds;
            datas.Add(data);

            ChartTools.MSLine msline = new ChartTools.MSLine(names, datas, "ShouYiBiLVLine", "showflash");
            return msline.ToString();
        }

        /// <summary>
        /// Tick分布图
        /// </summary>
        /// <param name="ticks"></param>
        /// <param name="playdiv"></param>
        /// <param name="title"></param>
        /// <param name="functionName"></param>
        /// <returns></returns>
        public static string TickPie(List<Models.View.OperatorDayTick> ticks, string playdiv, string title, string functionName)
        {
            List<ChartTools.Pie3DData> datas = new List<ChartTools.Pie3DData>();
            double max = 0;
            if (ticks.Count > 0)
            {
                max = ticks.Max(a => a.Count);
            }
            var query = ticks.Where(a => a.Count > 0);
            if (query.Count() == 0)
            {
                ChartTools.Pie3DData data = new ChartTools.Pie3DData();
                data.Label = "没有记录";
                data.Value = 1;
                data.IsSelected = true;
                datas.Add(data);
            }
            else
            {
                foreach (Models.View.OperatorDayTick tick in ticks)
                {
                    ChartTools.Pie3DData data = new ChartTools.Pie3DData();
                    if (tick.Tick == 11)
                    {
                        data.Label = "10个以上";
                    }
                    else
                    {
                        data.Label = tick.Tick + "个";
                    }

                    if (tick.Count == max)
                    {
                        data.IsSelected = true;
                    }
                    else
                    {
                        data.IsSelected = false;
                    }
                    data.Value = tick.Count;
                    datas.Add(data);
                }
            }


            ChartTools.Pie3D pie3d = new ChartTools.Pie3D(datas, functionName, playdiv, title, 130);
            return pie3d.ToString();
        }


        public static string GetMonthBenefitString(List<Models.View.OperatorDayChange> datas)
        {
            ChartTools.Col3DLineDY3Data data = new ChartTools.Col3DLineDY3Data();
            data.ColName = "平仓盈亏";
            data.LineName = "累计平仓盈亏";
            List<double> coldatas = new List<double>();
            Random rand = new Random();
            List<string> names = new List<string>();
            for (int i = 0; i < datas.Count; i++)
            {
                coldatas.Add(datas[i].Profit);
                names.Add(datas[i].TradeHistory.DPdate.ToString());
            }
            data.ColDatas = coldatas;
            List<double> coldatas2 = new List<double>();
            double sum = 0;
            for (int i = 0; i < datas.Count; i++)
            {
                sum += datas[i].Profit;
                coldatas.Add(sum);
            }
            data.LineDatas = coldatas2;


            data.Labels = names;
            ChartTools.Col3DLineDY3 d3 = new ChartTools.Col3DLineDY3(data, "MonthBenefit", "showflash2", "月分析图");
            return d3.ToString();
        }


        /// <summary>
        /// 公司历史数据的今天和去年同期的月比较图
        /// </summary>
        /// <param name="month"></param>
        /// <param name="year"></param>
        /// <param name="db"></param>
        /// <returns></returns>
        public static string DayShouyilv(List<Models.Day.CompanyDayChange> thisYearChanges, List<Models.Day.CompanyDayChange> preYearChanges)
        {
            List<int> datalist1 = new List<int>();
            List<int> datalist2 = new List<int>();
            List<ChartTools.MSAreaData> ds = new List<ChartTools.MSAreaData>();
            ChartTools.MSAreaData datas = new ChartTools.MSAreaData();
            datas.LabelName = "去年同期";
            List<double> data = new List<double>();
            foreach (Models.Day.CompanyDayChange d in preYearChanges)
            {
                datalist1.Add(d.TradeHistory.DPdate);
            }
            ChartTools.MSAreaData datas2 = new ChartTools.MSAreaData();
            datas2 = new ChartTools.MSAreaData();
            datas2.LabelName = "今年";
            List<double> data2 = new List<double>();
            foreach (Models.Day.CompanyDayChange d in thisYearChanges)
            {
                datalist2.Add(d.TradeHistory.DPdate);
            }
            var list = CompareList(datalist1, datalist2);

            List<string> labels = new List<string>();
            foreach (int i in list)
            {
                labels.Add(i.ToString());
            }


            foreach (int i in list)
            {
                var query = preYearChanges.Where(a => a.TradeHistory.DPdate == i);
                if (query.Count() > 0)
                {
                    data.Add(query.First().Profit);
                }
                else
                {
                    data.Add(0);
                }
            }
            datas.Datas = data;
            ds.Add(datas);
            foreach (int i in list)
            {
                var query = thisYearChanges.Where(a => a.TradeHistory.DPdate == i);
                if (query.Count() > 0)
                {
                    data2.Add(query.First().Profit);
                }
                else
                {
                    data2.Add(0);
                }
            }
            datas2.Datas = data2;
            ds.Add(datas2);
            ChartTools.MSArea pie3d = new ChartTools.MSArea(labels, ds, "DayShouyilv", "showflash", "收益", "", "");
            return pie3d.ToString();
        }


        private static List<int> CompareList(List<int> list1, List<int> list2)
        {
            List<int> list = new List<int>();
            foreach (int i in list1)
            {
                list.Add(i);
            }
            foreach (int i in list2)
            {
                if (!list.Contains(i))
                {
                    list.Add(i);
                }
            }
            list.Sort();
            return list;
        }


        /// <summary>
        /// 公司历史数据里面当月收益率和当月累计收益图
        /// </summary>
        /// <param name="groupId"></param>
        /// <param name="month"></param>
        /// <param name="year"></param>
        /// <param name="db"></param>
        /// <returns></returns>
        public static string CompanyMonthBenefitString(List<Models.Day.CompanyDayChange> companyDayChanges)
        {
            ChartTools.Col3DLineDY3Data data = new ChartTools.Col3DLineDY3Data();
            data.ColName = "当月收益率";
            data.LineName = "累计收益率";
            List<double> coldatas = new List<double>();
            foreach (Models.Day.CompanyDayChange _data in companyDayChanges)
            {
                coldatas.Add(_data.Yield);
            }
            data.ColDatas = coldatas;
            List<double> coldatas2 = new List<double>();
            double _sum = 0f;
            foreach (Models.Day.CompanyDayChange _data in companyDayChanges)
            {
                _sum += _data.Yield;
                coldatas2.Add(_sum);
            }
            data.LineDatas = coldatas2;
            List<string> names = new List<string>();
            foreach (Models.Day.CompanyDayChange _data in companyDayChanges)
            {
                names.Add(_data.TradeHistory.DPdate.ToString());
            }

            data.Labels = names;
            ChartTools.Col3DLineDY3 d3 = new ChartTools.Col3DLineDY3(data, "YearBenefit", "showflash2", "收益率示意图", "changeMonth", "$");
            return d3.ToString();
        }

        public static string MonthAreaBenefitPic(List<Models.Day.GroupDayChange> GroupDayChanges)
        {
            ChartTools.MSAreaData datas = new ChartTools.MSAreaData();
            datas.LabelName = "";
            List<double> data = new List<double>();
            foreach (Models.Day.GroupDayChange s in GroupDayChanges)
            {
                data.Add(s.Yield);
            }

            datas.Datas = data;
            List<string> labels = new List<string>();
            foreach (Models.Day.GroupDayChange s in GroupDayChanges)
            {
                labels.Add(s.TradeHistory.DPdate.ToString() + "日");
            }

            List<ChartTools.MSAreaData> ds = new List<ChartTools.MSAreaData>();
            ds.Add(datas);
            ChartTools.MSArea pie3d = new ChartTools.MSArea(labels, ds, "MonthAreaBenefitPic", "showflash2", "收益率", "日期", "收益率");
            return pie3d.ToString();
        }

        public static string MonthBenefitString(List<Models.Day.GroupDayChange> groupDayChanges)
        {
            ChartTools.Col3DLineDY3Data data = new ChartTools.Col3DLineDY3Data();
            data.ColName = "当月收益率";
            data.LineName = "累计收益率";
            List<double> coldatas = new List<double>();
            foreach (Models.Day.GroupDayChange _data in groupDayChanges)
            {
                coldatas.Add(_data.Profit);
            }
            data.ColDatas = coldatas;
            List<double> coldatas2 = new List<double>();
            double _sum = 0f;
            foreach (Models.Day.GroupDayChange _data in groupDayChanges)
            {
                _sum += _data.Profit;
                coldatas2.Add(_sum);
            }
            data.LineDatas = coldatas2;
            List<string> names = new List<string>();
            foreach (Models.Day.GroupDayChange _data in groupDayChanges)
            {
                names.Add(_data.TradeHistory.DPdate.ToString());
            }

            data.Labels = names;
            ChartTools.Col3DLineDY3 d3 = new ChartTools.Col3DLineDY3(data, "YearBenefit", "showflash2", "收益率示意图", "changeMonth", "$");
            return d3.ToString();
        }

        public static string GroupPie(List<Models.Sys.Operator> operators, List<Models.View.OperatorMonthSum> operatorMonthSums)
        {
            List<ChartTools.Pie3DData> datas = new List<ChartTools.Pie3DData>();
            foreach (Models.Sys.Operator op in operators)
            {
                ChartTools.Pie3DData data = new ChartTools.Pie3DData();
                data.Label = op.UName;
                // data.IsSelected = true;
                Models.View.OperatorMonthSum sum = operatorMonthSums.Where(a => a.OperatorId == op.Id).FirstOrDefault();
                data.Value = sum.DayCount;
                datas.Add(data);
            }
            ChartTools.Pie3D pie3d = new ChartTools.Pie3D(datas, "GroupPie", "showflash", "盈利占比", 200);
            return pie3d.ToString();
        }



        public static string ShouYiBiLVLine(List<Models.View.OperatorDayChange> operatorDayChanges)
        {
            List<string> names = new List<string>();
            foreach (Models.View.OperatorDayChange change in operatorDayChanges)
            {
                names.Add(change.TradeHistory.DPdate.ToString());
            }
            List<ChartTools.Series> datas = new List<ChartTools.Series>();
            ChartTools.Series data = new ChartTools.Series();
            // data.Color = "1D8BD1";
            data.Name = "收益率";
            List<double> ds = new List<double>();
            foreach (Models.View.OperatorDayChange change in operatorDayChanges)
            {
                ds.Add(change.Yield);
            }
            data.Datas = ds;
            datas.Add(data);

            ChartTools.MSLine msline = new ChartTools.MSLine(names, datas, "ShouYiBiLVLine", "showflash5");
            return msline.ToString();
        }

        public static string GetOperatorAllBenefitPie(List<Models.View.OperatorDayTradeInfoData> operatorDayTradeInfoDatas, bool win)
        {
            List<ChartTools.Pie3DData> datas = new List<ChartTools.Pie3DData>();
            ChartTools.Pie3DData data = new ChartTools.Pie3DData();
            data.Label = "9:00-9:30";
            data.IsSelected = true;
            data.Value = operatorDayTradeInfoDatas.Where(a => a.Clock == 1).Sum(a => a.SumValue);
            datas.Add(data);
            data = new ChartTools.Pie3DData();
            data.Label = "9:30-10:00";
            data.IsSelected = false;
            data.Value = operatorDayTradeInfoDatas.Where(a => a.Clock == 2).Sum(a => a.SumValue);
            datas.Add(data);
            data = new ChartTools.Pie3DData();
            data.Label = "10:00-10:30";
            data.IsSelected = false;
            data.Value = operatorDayTradeInfoDatas.Where(a => a.Clock == 3).Sum(a => a.SumValue);
            datas.Add(data);
            data = new ChartTools.Pie3DData();
            data.Label = "10:30-11:00";
            data.IsSelected = false;
            data.Value = operatorDayTradeInfoDatas.Where(a => a.Clock == 4).Sum(a => a.SumValue);
            datas.Add(data);
            data = new ChartTools.Pie3DData();
            data.Label = "13:00-13:30";
            data.IsSelected = false;
            data.Value = operatorDayTradeInfoDatas.Where(a => a.Clock == 5).Sum(a => a.SumValue);
            datas.Add(data);
            data = new ChartTools.Pie3DData();
            data.Label = "13:30-14:00";
            data.IsSelected = false;
            data.Value = operatorDayTradeInfoDatas.Where(a => a.Clock == 6).Sum(a => a.SumValue);
            datas.Add(data);
            data = new ChartTools.Pie3DData();
            data.Label = "14:00-14:30";
            data.IsSelected = false;
            data.Value = operatorDayTradeInfoDatas.Where(a => a.Clock == 7).Sum(a => a.SumValue);
            datas.Add(data);
            data = new ChartTools.Pie3DData();
            data.Label = "14:30-15:00";
            data.IsSelected = false;
            data.Value = operatorDayTradeInfoDatas.Where(a => a.Clock == 8).Sum(a => a.SumValue);
            datas.Add(data);
            ChartTools.Pie3D pie3d;

            var query3 = datas.Where(a => a.Value > 0);
            if (query3.Count() == 0)
            {
                datas = new List<Pie3DData>();
                data = new ChartTools.Pie3DData();
                data.Label = "没有记录";
                data.IsSelected = false;
                data.Value = 1;
                datas.Add(data);
            }

            if (win)
            {
                pie3d = new ChartTools.Pie3D(datas, "YearPie2", "showflash3", "盈利按时间分布", 160);
            }
            else
            {
                pie3d = new ChartTools.Pie3D(datas, "YearPie3", "showflash4", "亏损按时间分布", 160);
            }

            return pie3d.ToString();
        }

        /// <summary>
        /// 得到交易员某月的交易曲线(OK)
        /// </summary>
        /// <param name="month"></param>
        /// <param name="year"></param>
        /// <param name="opeartorid"></param>
        /// <param name="db"></param>
        /// <returns></returns>
        public static string GetOperatorMonthYieldString(List<Models.View.OperatorDayChange> operatorDayChanges)
        {
            ChartTools.Col3DLineDY3Data data = new ChartTools.Col3DLineDY3Data();
            data.ColName = "当月收益率";
            data.LineName = "累计收益率";
            List<double> coldatas = new List<double>();
            List<double> coldatas2 = new List<double>();
            List<string> names = new List<string>();
            double total = 0;
            foreach (Models.View.OperatorDayChange change in operatorDayChanges)
            {
                coldatas.Add(change.Yield);
                total += change.Yield;
                coldatas2.Add(total);
                names.Add(change.TradeHistory.DPdate.ToString());
            }
            data.ColDatas = coldatas;
            data.LineDatas = coldatas2;
            data.Labels = names;
            ChartTools.Col3DLineDY3 d3 = new ChartTools.Col3DLineDY3(data, "YearBenefit", "showflash", "收益示意图", "changeMonth", "$");
            return d3.ToString();
        }

        /// <summary>
        /// 交易员月对比图像(OK)
        /// </summary>
        /// <param name="month"></param>
        /// <param name="year"></param>
        /// <param name="operatorid"></param>
        /// <param name="db"></param>
        /// <returns></returns>
        public static string MonthDiffBar(Models.View.OperatorMonthSum operatorMonthSum)
        {
            List<ChartTools.Column3DData> datas = new List<ChartTools.Column3DData>();

            ChartTools.Column3DData data = new ChartTools.Column3DData();
            data.Name = "平仓盈亏";
            data.Value = Convert.ToDecimal(operatorMonthSum.Profit);
            datas.Add(data);
            data = new ChartTools.Column3DData();
            data.Name = "净利润";
            data.Value = Convert.ToDecimal(operatorMonthSum.DayCount);
            datas.Add(data);
            data = new ChartTools.Column3DData();
            data.Name = "手续费";
            data.Value = Convert.ToDecimal(operatorMonthSum.Free);
            datas.Add(data);


            ChartTools.Column3D pie3d = new ChartTools.Column3D("收益对比图", "", "", datas, "", "YearBar", "showflash2");
            return pie3d.ToString();
        }
    }
}
